package com.xiexie.order.controller;

import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Description
 * @Date 2022-04-07 14:46
 * @Author xie
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/add")
    @Trace
    @Tag(key = "list", value = "returnedObj")
    @Tags({@Tag(key = "list", value = "returnedObj"), @Tag(key = "list", value = "returnedObj")})
    public String add() {
        System.out.println("下单成功");

        //String msg = restTemplate.getForObject("http://localhost:8011/stock/reduct", String.class);

        String msg = restTemplate.getForObject("http://stock-server/stock/reduct", String.class);

        return "Hello order add " + msg;
    }

    @RequestMapping("/header")
    public String header(@RequestHeader("X-Request-color") String color) {
        System.out.println("gateWay获取请求头X‐Request‐color：" + color);
        return color;
    }


    @RequestMapping("/parameter")
    public String parameter(@RequestParam("color") String color) {
        System.out.println("gateWay获取参数color：" + color);
        return color;
    }
}
